<?php
namespace App\Api;

use App\Domain\UserReportClassifyDomain;
use PhalApi\Api;
use App\Domain\Dynamic as Domain_Dynamic;
use function PhalApi\DI;
use function PhalApi\T;

/**
 * 动态
 */

class Dynamic extends Api {

	public function getRules() {
        return array(
            'setDynamic' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'title' => array('name' => 'title', 'type' => 'string', 'desc' => '标题'),
				'thumb' => array('name' => 'thumb', 'type' => 'string', 'desc' => '图片地址集合'),
				'video_thumb' => array('name' => 'video_thumb', 'type' => 'string', 'desc' => '视频封面'),
				'href' => array('name' => 'href', 'type' => 'string', 'desc' => '视频地址'),
				'voice' => array('name' => 'voice', 'type' => 'string', 'desc' => '语音地址'),
				'length' => array('name' => 'length', 'type' => 'int',  'desc' => '语音长度'),
				'lat' => array('name' => 'lat', 'type' => 'string',  'desc' => '维度'),
				'lng' => array('name' => 'lng', 'type' => 'string',  'desc' => '经度'),
                'width' => array('name' => 'width', 'type' => 'string',  'desc' => '宽度'),
				'height' => array('name' => 'height', 'type' => 'string',  'desc' => '高度'),
				'city' => array('name' => 'city', 'type' => 'string',  'desc' => '城市'),
				'type' => array('name' => 'type', 'type' => 'int','default'=>0, 'desc' => '动态类型：0：纯文字；1：文字+图片；2：文字+视频；3：文字+音频'),
				'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名 uid  thumb  video_thumb href  type'),
			),
			'setComment' => array(
                'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1,  'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户Token'),
				'dynamicid' => array('name' => 'dynamicid', 'type' => 'int', 'min' => 1,'desc' => '动态ID'),
				'touid' => array('name' => 'touid', 'type' => 'int', 'default'=>0, 'desc' => '回复的评论UID'),
                'commentid' => array('name' => 'commentid', 'type' => 'int',  'default'=>0,  'desc' => '回复的评论commentid'),
                'parentid' => array('name' => 'parentid', 'type' => 'int',  'default'=>0,  'desc' => '回复的评论ID'),
                'content' => array('name' => 'content', 'type' => 'string',  'default'=>'', 'desc' => '内容'),
                'type'=>array('name'=>'type','type'=>'int','default'=>'0','desc'=>'类型，0文字，1语音'),
                'voice'=>array('name'=>'voice','type'=>'string','desc'=>'语音'),
                'length'=>array('name'=>'length','type'=>'int','desc'=>'时长'),
            ),
            'delComment' => [
                'userId' => [
                    'name' => 'userId', 'type' => 'int', 'desc' => '用户ID'
                ],
                'token' => [
                    'name' => 'token', 'type' => 'string', 'desc' => '用户token'
                ],
                'commentId' => [
                    'name' => 'commentId', 'type' => 'int', 'desc' => '评论ID'
                ],
//                'dynamicId' => [
//                    'name' => 'dynamicId', 'type' => 'int', 'desc' => '动态ID'
//                ]
            ],
            'addLike' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'dynamicid' => array('name' => 'dynamicid', 'type' => 'int', 'desc' => '动态ID'),
                'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名 uid  dynamicid'),
			),
			'addCommentLike' => array(
            	'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1,  'desc' => '用户ID'),
            	'token' => array('name' => 'token', 'type' => 'string','desc' => '用户Token'),
                'commentid' => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'desc' => '评论/回复 ID'),
				'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名 uid  commentid'),
            ),
            'myVideo' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'p' => array('name' => 'p', 'type' => 'int', 'desc' => '页码'),
			),
            'delDynamic' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'dynamicid' => array('name' => 'dynamicid', 'type' => 'int', 'desc' => '动态ID'),
			),
            'setReport' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'dynamicid' => array('name' => 'dynamicid', 'type' => 'int', 'desc' => '动态ID'),
				'content' => array('name' => 'content', 'type' => 'string', 'desc' => '内容'),
                'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名  uid   dynamicid  content'),
			),
            
            'getHomeDynamic' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
				'token' => array('name' => 'token', 'type' => 'string', 'desc' => '用户token'),
				'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'desc' => '主播ID'),
				'p' => array('name' => 'p', 'type' => 'int', 'desc' => '页码'),
			),
			
			 'getAttentionDynamic' => array(
            	'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1,'desc' => '用户ID'),
            	'token' => array('name' => 'token', 'type' => 'string','desc' => '用户Token'),
            	'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1, 'desc' => '页数'),
            ),
			'getDynamicList' => array(
            	'uid' => array('name' => 'uid', 'type' => 'int',  'desc' => '用户ID'),
            	'type' => array('name' => 'type', 'type' => 'int',  'desc' => '动态类型'),
            	'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1, 'desc' => '页数'),
            ),
			'getComments' => array(
                'uid' => array('name' => 'uid', 'type' => 'int','desc' => '用户ID'),
                'dynamicid' => array('name' => 'dynamicid', 'type' => 'int', 'min' => 1, 'desc' => '动态ID'),
                'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1, 'desc' => '页数'),
            ),
			'getReplys' => array(
				'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
                'commentid' => array('name' => 'commentid', 'type' => 'int', 'min' => 1, 'desc' => '评论ID'),
                'last_replyid' => array('name' => 'last_replyid', 'type' => 'int', 'min' => 0, 'default'=>0,  'desc' => '上一次请求时最小的回复id，第一次请求时为评论列表里的回复id'),
                'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1, 'desc' => '页数'),
            ),
            'getLike' => array(
                'uid' => array('name' => 'uid', 'type' => 'int','desc' => '用户ID'),
                'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1, 'desc' => '页数'),
            ),
            'getReport' => [
                'langId' => ['name' => 'langId', 'type' => 'int','desc' => '语种ID']
            ],

         
            
        );
	}
	

    /**
     * 发布动态
     * @desc 用于用户发布动态
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string msg 提示信息
     */
	public function setDynamic() {
        
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$title=\App\checkNull($this->title);
		$thumb=\App\checkNull($this->thumb);
		$video_thumb=\App\checkNull($this->video_thumb);
		$href=\App\checkNull($this->href);
		$lat=\App\checkNull($this->lat);
		$lng=\App\checkNull($this->lng);
		$city=\App\checkNull($this->city);
		$type=\App\checkNull($this->type);
		$sign=\App\checkNull($this->sign);
		$voice=\App\checkNull($this->voice);
		$length=\App\checkNull($this->length);
		$width=\App\checkNull($this->width);
		$height=\App\checkNull($this->height);
        
        if($uid<1 || $token==''){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
     
        $checkdata=array(
            'uid'=>$uid,
            'type'=>$type,
        );
        
       $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
         
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}

		$is_has_sensitive=\App\checkSensitiveWords($title);

        if($is_has_sensitive){
        	$rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('动态标题输入非法,请重新输入');
			return $rs;
        }
        
        $data=[
            'uid'=>$uid,
            'title'=>$title,
            'thumb'=>$thumb,
            'video_thumb'=>$video_thumb,
            'href'=>$href,
            'voice'=>$voice,
            'length'=>$length,
            'lat'=>$lat,
            'lng'=>$lng,
            'width'=>$width,
            'height'=>$height,
            'city'=>$city,
            'type'=>$type,
            "likes"=>0,
			"comments"=>0,
        ];
        //ggg
        if(!empty($data['video_thumb'])){
            $imageInfo = getimagesize(\App\get_upload_path($data['video_thumb']));
            $data['ratio'] = bcdiv($imageInfo[1],$imageInfo[0],2);
        }
        $domain = new Domain_Dynamic();
		$result=$domain->setDynamic($data);
        
		return $result;
        
	}
	
	/**
     * 评论/回复
     * @desc 用于用户评论/回复 别人动态
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return int info[0].isattent 对方是否关注我
     * @return int info[0].u2t 我是否拉黑对方
     * @return int info[0].t2u 对方是否拉黑我
     * @return int info[0].comments 评论总数
     * @return int info[0].replys 回复总数
     * @return string msg 提示信息
     */
	public function setComment() {
        $rs = array('code' => 0, 'msg' => \PhalApi\T('评论成功'), 'info' => array());
		
		$uid=$this->uid;
		$token=\App\checkNull($this->token);
		$touid=$this->touid;
		$dynamicid=$this->dynamicid;
		$commentid=$this->commentid;
		$parentid=$this->parentid;
		$content=\App\checkNull($this->content);
		$type=\App\checkNull($this->type);
		$voice=\App\checkNull($this->voice);
		$length=\App\checkNull($this->length);
	
		$checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}else if($checkToken==10020){
			$rs['code'] = 700;
			$rs['msg'] = \PhalApi\T('该账号已被禁用');
			return $rs;
		}
		
		
		$domain = new Domain_Dynamic();
		
		$info = $domain->getDynamic($dynamicid);
        if(!$info){
            $rs['code']=1003;
			$rs['msg']=\PhalApi\T('动态不存在');
			return $rs;
        }
		
		
		if($touid>0){
			$isattent=\App\isAttention($touid,$uid);
			$u2t = \App\isBlack($uid,$touid);
			$t2u = \App\isBlack($touid,$uid);
			if($t2u==1){
				$rs['code'] = 1000;
				$rs['msg'] = \PhalApi\T('对方暂时拒绝接收您的消息');
				return $rs;
			}
		}
        if($type==1){
            if($voice==''){
                $rs['code'] = 1001;
				$rs['msg'] = \PhalApi\T('请录入语音');
				return $rs;
            }
        }else{
            if($content==''){
                $rs['code'] = 1002;
				$rs['msg'] = \PhalApi\T('请输入内容');
				return $rs;
            }

            $is_has_sensitive=\App\checkSensitiveWords($content);

	        if($is_has_sensitive){
	        	$rs['code'] = 1001;
				$rs['msg'] = \PhalApi\T('输入非法,请重新输入');
				return $rs;
	        }
	        
        }
		if($commentid==0 && $commentid!=$parentid){
			$commentid=$parentid;
		}
	
		$data=array(
			'uid'=>$uid,
			'touid'=>$touid,
			'dynamicid'=>$dynamicid,
			'commentid'=>$commentid,
			'parentid'=>$parentid,
			'content'=>$content,
			'addtime'=>time(),
			'type'=>$type,
			'voice'=>$voice,
			'length'=>$length,
		);
		
        $domain = new Domain_Dynamic();
        $result = $domain->setComment($data);
		$info=array(
			'isattent'=>'0',
			'u2t'=>'0',
			't2u'=>'0',
			'comments'=>$result['comments'],
			'replys'=>$result['replys'],
			//'current'=>$result['current'],
		);
		if($touid>0){
			$isattent=\App\isAttention($touid,$uid);
			$u2t = \App\isBlack($uid,$touid);
			$t2u = \App\isBlack($touid,$uid);
			
			$info['isattent']=(string)$isattent;
			$info['u2t']=(string)$u2t;
			$info['t2u']=(string)$t2u;
		}
		
		$rs['info'][0]=$info;
		
		if($parentid!=0){
			$rs['msg']=\PhalApi\T('回复成功');		
		}
        return $rs;
    }	

	
    /**
     * 我的动态
     * @desc 用于获取我的动态
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].id 视频ID  
     * @return string info[].title 标题  
     * @return string info[].thumb 封面  
     * @return string info[].href 链接  
     * @return string info[].likes 点赞数
     * @return string info[].views 观看数  
     * @return string info[].shares 分享数  
     * @return string info[].isprivate 是否私密，0否1是  
     * @return string info[].coin 价格
     * @return string info[].status 审核状态，0审核中，1通过，2拒绝
     * @return string info[].reason 失败原因
     * @return object info[].userinfo 用户信息
     * @return string info[].userinfo.id 用户ID  
     * @return string info[].userinfo.user_nickname 昵称
     * @return string info[].userinfo.avatar 头像
     * @return string info[].userinfo.avatar_thumb 小头像
     * @return string msg 提示信息
     */
	public function myVideo() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$p=\App\checkNull($this->p);
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Dynamic();
		$list=$domain->myVideo($uid,$p);
        
        $rs['info']=$list;
        
        return $rs;
	}

    /**
     * 点赞
     * @desc 用于更新动态点赞
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].islike 是否点赞，0否1是
     * @return string info[0].nums 数量
     * @return string msg 提示信息
     */
	public function addLike() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('点赞成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$dynamicid=\App\checkNull($this->dynamicid);
		$sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $dynamicid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'dynamicid'=>$dynamicid,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Dynamic();
		$result=$domain->addLike($uid,$dynamicid);
        
		return $result;
        
	}
	
		/**
     * 评论/回复 点赞
     * @desc 用于评论/回复 点赞数累计
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].islike 是否点赞 
     * @return string info[0].likes 点赞数量
     * @return string msg 提示信息
     */
	public function addCommentLike() {
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());

        $uid=$this->uid;
        $token=\App\checkNull($this->token);
        $commentid=$this->commentid;
        $sign=$this->sign;

		if($uid<1 || $token=='' || $commentid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkdata=array(
            'uid'=>$uid,
            'commentid'=>$commentid,
        );
        
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        $domain = new Domain_Dynamic();
        $res= $domain->addCommentLike($uid,$commentid);
        
        return $res;
    }	

    /**
     * 删除动态
     * @desc 用于用户删除动态
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string msg 提示信息
     */
	public function delDynamic() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$dynamicid=\App\checkNull($this->dynamicid);
        
        if($uid<1 || $token=='' || $dynamicid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Dynamic();
		$result=$domain->delDynamic($uid,$dynamicid);
        
		return $result;
        
	}

    /**
     * 举报分类
     * @desc 用于举报分类
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].name 分类名 
     * @return string msg 提示信息
     */
	public function getReport() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        $list = UserReportClassifyDomain::getReportClassify(3,$this->langId);
//        $domain = new Domain_Dynamic();
//		$list=$domain->getReport();
        
        $rs['info']=$list;
        
		return $rs;
        
	}
    
    /**
     * 举报
     * @desc 用于用户举报动态
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string msg 提示信息
     */
	public function setReport() {
        
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$dynamicid=\App\checkNull($this->dynamicid);
		$content=\App\checkNull($this->content);
		$sign=\App\checkNull($this->sign);
        
        if($uid<1 || $token=='' || $dynamicid <1 || $content==''){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }
        $checkdata=array(
            'uid'=>$uid,
            'dynamicid'=>$dynamicid,
            'content'=>$content,
        );
        $issign=\App\checkSign($checkdata,$sign);
        if(!$issign){
            $rs['code']=1002;
			$rs['msg']=\PhalApi\T('签名错误');
			return $rs;	
        }
        
        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Dynamic();
		$result=$domain->setReport($uid,$dynamicid,$content);
        
		return $result;
        
	}

    /**
     * 个人动态
     * @desc 用于获取个人主页动态
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[].id 视频ID  
     * @return string info[].title 标题  
     * @return string info[].thumb 封面  
     * @return string info[].href 链接  
     * @return string info[].likes 点赞数
     * @return string info[].islike 是否点赞，0否1是
     * @return object info[].userinfo 用户信息
     * @return string info[].userinfo.id 用户ID  
     * @return string info[].userinfo.user_nickname 昵称
     * @return string info[].userinfo.avatar 头像
     * @return string info[].userinfo.avatar_thumb 小头像
     * @return string msg 提示信息
     */
	public function getHomeDynamic() {
        
        $rs = array('code' => 0, 'msg' => \PhalApi\T('操作成功'), 'info' => array());
        
        $uid=\App\checkNull($this->uid);
		$token=\App\checkNull($this->token);
		$liveuid=\App\checkNull($this->liveuid);
		$p=\App\checkNull($this->p);
        
        if($uid<1 || $token=='' || $liveuid <1 ){
            $rs['code'] = 1001;
			$rs['msg'] = \PhalApi\T('信息错误');
			return $rs;
        }

        $checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}
        
        
        $domain = new Domain_Dynamic();
		$list=$domain->getHomeDynamic($uid,$liveuid,$p);
        
		return $list;
        
	}
	/**
     * 获取关注动态
     * @desc 用于获取关注动态
     * @return int code 操作码，0表示成功
     * @return array info 视频列表
     * @return array info[].userinfo 用户信息
     * @return string info[].datetime 格式后的发布时间
	 * @return string info[].islike 是否点赞 
	 * @return string info[].comments 评论总数
     * @return string info[].likes 点赞数
     * @return string msg 提示信息
     */
	public function getAttentionDynamic() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());

        $uid=$this->uid;
		$token=\App\checkNull($this->token);
		$p=$this->p;
		$checkToken=\App\checkToken($uid,$token);
		if($checkToken==700){
			$rs['code'] = $checkToken;
			$rs['msg'] = \PhalApi\T('您的登陆状态失效，请重新登陆！');
			return $rs;
		}

		$key='attention_dynamicLists_'.$uid.'_'.$p;
        $info=\App\getcache($key);

        if(!$info){
        	$domain = new Domain_Dynamic();
        	$info=$domain->getAttentionDynamic($uid,$p);
        	if($info==0){
        		 $rs['code']=0;
                $rs['msg']=\PhalApi\T("暂无动态列表");
                return $rs;
        	}
        }
        
        $rs['info'] = $info;

        return $rs;
    }

	
	/**
     * 获取动态列表
     * @desc 用于 获取动态列表
     * @return int code 操作码，0表示成功
     * @return array info 视频列表
     * @return array info[].userinfo 用户信息
     * @return string info[].datetime 格式后的发布时间
	 * @return string info[].islike 是否点赞 
	 * @return string info[].comments 评论总数
     * @return string info[].likes 点赞数
     * @return string msg 提示信息
     */
	public function getDynamicList() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());

        $uid=$this->uid;
		$p=$this->p;
		$type=$this->type;
		
		$domain = new Domain_Dynamic();
		$info=$domain->getDynamicList($uid,$p,$type);
		if($info==0){
			 $rs['code']=0;
			$rs['msg']=\PhalApi\T("暂无动态列表");
			return $rs;
		}
        $rs['info'] = $info;

        return $rs;
    }	
	/**
     * 动态评论列表
     * @desc 用于获取动态评论列表
     * @return int code 操作码，0表示成功
     * @return array info 
     * @return string info[0].comments 评论总数
     * @return array info[0].commentlist 评论列表
     * @return object info[0].commentlist[].userinfo 用户信息
	 * @return string info[0].commentlist[].datetime 格式后的时间差
	 * @return string info[0].commentlist[].replys 回复总数
	 * @return string info[0].commentlist[].likes 点赞数
	 * @return string info[0].commentlist[].islike 是否点赞
	 * @return array info[0].commentlist[].replylist 回复列表
     * @return string msg 提示信息
     */
	public function getComments() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
		

        $domain = new Domain_Dynamic();
        $info= $domain->getComments($this->uid,$this->dynamicid,$this->p);
		if($info==0){
			$rs['code']=0;
			$rs['msg']=\PhalApi\T("暂无动态列表");
			return $rs;
		}
		$rs['info'][0]=$info;
        return $rs;
    }
    
    public function getLike() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
		$uid=\App\checkNull($this->uid);
		$p=$this->p;
		$domain = new Domain_Dynamic();
		$info = $domain->getLike($uid,$p);
        if($info == 0){
			$rs['code']=0;
			$rs['msg']=\PhalApi\T("暂无动态列表");
			return $rs;
		}
        $rs['info'] = $info;
        return $rs;
    }

	/**
     * 回复列表
     * @desc 用于获取动态评论列表
     * @return int code 操作码，0表示成功
     * @return array info 评论列表
     * @return object info[].userinfo 用户信息
	 * @return string info[].datetime 格式后的时间差
	 * @return object info[].tocommentinfo 回复的评论的信息
	 * @return object info[].tocommentinfo.content 评论内容
	 * @return string info[].likes 点赞数
	 * @return string info[].islike 是否点赞
     * @return string msg 提示信息
     */
	public function getReplys() {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
		
        $domain = new Domain_Dynamic();
        $res = $domain->getReplys($this->uid,$this->commentid,$this->last_replyid,$this->p);

        $rs['info'][0]['lists']=$res['lists'];
        $rs['info'][0]['replys']=$res['replys'];
        return $rs;
    }

    /**
     * 删除平林
     * @return array
     */
    public function delComment()
    {
        $userId = \App\checkNull($this->userId);
        $token = \App\checkNull($this->token);
        $commentId = \App\checkNull($this->commentId);
//        $dynamicId = \App\checkNull($this->dynamicId);
        // 判断回复是否是当前用户发表的评论
        $comment = DI()->notorm->dynamics_comments->where('id = '.$commentId)->fetchOne();
        if ($comment) {
            if ($comment['uid'] != $userId) {
                return [
                    'code' => -1,
                    'msg' => T("该动态不属于你，不能删除"),
                    'info' => []
                ];
            }
        }else {
            return [
                'code' => -1,
                'msg' => T("动态不存在"),
                'info' => []
            ];
        }
        // 获取当前评论是否是顶级评论
        try {
            if (!empty($comment['parentid'])) {
                // 只删除当前评论
                $where = 'commentid='.$commentId;
                DI()->notorm->dynamics_comments->where($where)->delete();
            }else {
                $where = 'parentid='.$commentId;
                DI()->notorm->dynamics_comments->where($where)->delete();
            }
            // 删除当前评论
            DI()->notorm->dynamics_comments->where('id='.$commentId)->delete();
        }catch (\Exception $e) {
            return [
                'code' => -1,
                'msg' => T($e->getMessage()),
                'info' => []
            ];
        }
        return [
            'code' => 0,
            'msg' => T('操作成功'),
            'info' => []
        ];
    }

    
}
